package org.fujay.langchain4jserver.domain.knowledge.exception;

import org.fujay.langchain4jserver.domain.knowledge.vo.KnowledgeBaseId;

/**
 * 当尝试访问或操作不存在的知识库时抛出此异常。
 */
public class KnowledgeBaseNotFoundException extends RuntimeException { // 或继承自定义业务异常基类

    private static final String MESSAGE_TEMPLATE = "未找到 ID 为 [%s] 的知识库。";

    public KnowledgeBaseNotFoundException(KnowledgeBaseId knowledgeBaseId) {
        super(
                String.format(
                        MESSAGE_TEMPLATE, knowledgeBaseId != null ? knowledgeBaseId.value() : "<null>"));
    }

    public KnowledgeBaseNotFoundException(KnowledgeBaseId knowledgeBaseId, String message) {
        super(
                message != null
                        ? message
                        : String.format(
                        MESSAGE_TEMPLATE, knowledgeBaseId != null ? knowledgeBaseId.value() : "<null>"));
    }

    public KnowledgeBaseNotFoundException(KnowledgeBaseId knowledgeBaseId, Throwable cause) {
        super(
                String.format(
                        MESSAGE_TEMPLATE, knowledgeBaseId != null ? knowledgeBaseId.value() : "<null>"),
                cause);
    }

    public KnowledgeBaseNotFoundException(
            KnowledgeBaseId knowledgeBaseId, String message, Throwable cause) {
        super(
                message != null
                        ? message
                        : String.format(
                        MESSAGE_TEMPLATE, knowledgeBaseId != null ? knowledgeBaseId.value() : "<null>"),
                cause);
    }
}
